package org.example;

import org.apache.commons.codec.binary.Hex;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.codec.digest.HmacUtils;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

public class Encryptor {

    public String encrypt(String s) {
        MessageDigest sha256Digest = DigestUtils.getSha256Digest();
        String result = Hex.encodeHexString(sha256Digest.digest(s.getBytes(StandardCharsets.UTF_8)));
        return Hex.encodeHexString(HmacUtils.getHmacSha256(result.getBytes()).doFinal(result.getBytes()));

//        try {
//            MessageDigest sha256Digest = MessageDigest.getInstance("SHA-256");
//            String result = Hex.encodeHexString(sha256Digest.digest(s.getBytes(StandardCharsets.UTF_8)));
//            return Hex.encodeHexString(HmacUtils.getHmacSha256(result.getBytes()).doFinal(result.getBytes()));
//        } catch (NoSuchAlgorithmException e) {
//            e.printStackTrace();
//            return "error";
//        }


    }

    public static void main(String[] args) {
        Encryptor encryptor = new Encryptor();
        String s = "test";
        String result = encryptor.encrypt(s);
        System.out.println(result);
    }

    /**
     output: fdd04dcac94e9803a72e4268141f773e2024a8fe46ba19a263be22c5ca83e931
     **/

}